package gclib.inventory;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.Table;

/**
 *
 * @author Jason
 */
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="ITEM_TYPE", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("ITEM")
@Table(name="GC_ITEMS")
public class Item implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ITEM_ID", nullable=false, updatable=false)
    private Integer itemId;

    @Column(name="ITEM_NAME", nullable=false)
    private String name;

    @Lob
    @Column(name="ITEM_DESCRIPTION")
    private String description;

    @Column(name="ITEM_WEIGHT")
    private Double weight;

    public Item() {
    }

    public Item(String name, String description, Double weight) {
        this.name = name;
        this.description = description;
        this.weight = weight;
    }

    public Integer getItemId() {
        return itemId;
    }

    protected void setItemId(Integer itemId) {
        this.itemId = itemId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name){
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Double getWeight() {
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Item other = (Item) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if ((this.description == null) ? (other.description != null) : !this.description.equals(other.description)) {
            return false;
        }
        if (this.weight != other.weight && (this.weight == null || !this.weight.equals(other.weight))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 61 * hash + (this.itemId != null ? this.itemId.hashCode() : 0);
        return hash;
    }

    /**
     * Item's toString method.
     * @return
     */
    @Override
    public String toString() {
        StringBuilder result = new StringBuilder("Item [");
        result.append("itemId:").append(itemId).append(", ");
        result.append("name:").append(name).append(", ");
        result.append("description:").append(description).append(", ");
        result.append("weight:").append(weight);
        return result.append(']').toString();
    }
}
